﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Physio10Context;
using DatabaseManager;

namespace Physio_Clinic
{
    public partial class WebForm7 : System.Web.UI.Page
    {
        public Qf8soUser currentUser = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["currentUser"] != null)
            {
                currentUser = (Qf8soUser)Session["currentUser"];
            }


            if (!Page.IsPostBack)
            {
                CalendarOrder.SelectedDate = DateTime.Today;
            }
        }

        protected void Calendar1_SelectionChanged(object sender, EventArgs e)
        {

        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string value = (string)e.CommandArgument;

            if (e.CommandName == "ViewOrder")
            {
                Response.Redirect("./Invoice.aspx?bookId=" + value);
            }
            else
            {
                Booking book = PersistentManager.Instance.GetBooking(Convert.ToInt32(value));
                Drugorder order = PersistentManager.Instance.GetDrugOrderbyBook(book.BookId);

                PersistentManager.Instance.Delete(book);
                PersistentManager.Instance.Save();
                PersistentManager.Instance.Delete(order, currentUser.Username);
                PersistentManager.Instance.Save();

                Response.Redirect("./OrderReport.aspx");

            }
        }

        protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Button myButton = (Button)e.Row.Cells[0].Controls[0];
                Button myButton1 = (Button)e.Row.Cells[1].Controls[0];

                if (e.Row.DataItem != null)
                {
                    myButton.CommandArgument = ((Booking)e.Row.DataItem).BookId.ToString();
                    myButton1.CommandArgument = ((Booking)e.Row.DataItem).BookId.ToString();
                }
            }
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}